package com.example.travelcomponentdemo;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;

public class PopupsampleActivity extends Activity {
/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		    
		final Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
		btnOpenPopup.setOnClickListener(new View.OnClickListener(){
			@Override
			public void onClick(View arg0) {
				LayoutInflater layoutInflater 
						     = (LayoutInflater)getBaseContext()
						      .getSystemService(LAYOUT_INFLATER_SERVICE);  
				View popupView = layoutInflater.inflate(R.layout.popup, null);  
				final PopupWindow popupWindow = new PopupWindow(
										           popupView, 
										           LayoutParams.WRAP_CONTENT,  
										                 LayoutParams.WRAP_CONTENT);  
				
				Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
				final LinearLayout layout = (LinearLayout)popupView.findViewById(R.id.layout_txt);
				
				btnDismiss.setOnClickListener(new Button.OnClickListener(){
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						popupWindow.dismiss();
//						layout.setVisibility(View.VISIBLE);
				}});
				popupWindow.setTouchable(true);
				popupWindow.setFocusable(true);
				popupWindow.setOutsideTouchable(true);
				popupWindow.setBackgroundDrawable(new BitmapDrawable());
				popupWindow.setTouchInterceptor(new View.OnTouchListener() {
			        public boolean onTouch(View v, MotionEvent event) {
			            if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
			            	popupWindow.dismiss();
			                return true;
			            }
			            return false;
			        }
			    });
	
				popupWindow.showAsDropDown(btnOpenPopup, 0, 0);
		}});
	}    
}